<template>
	<view class="certificate">
		<template v-if="tableData.length">
			<signup-card3 v-for="(item,idx) of tableData" :key="idx" :examData="item"></signup-card3>
		</template>
		
		<template v-else>
			<no-data></no-data>
		</template>
		
		<u-loadmore :status="status" />
		<wyb-loading ref="loading"/>
		
		<tab-bar></tab-bar>
	</view>
</template>

<script>
	import tabBar from "@/components/tabBar.vue"
	import wybLoading from '@/components/wyb-loading/wyb-loading.vue'
	import signupCard3 from "@/components/signupCard3.vue"
	
	import {
		list
	} from "@/api/apiList/user.js"
	
	import {BASE_URL} from "@/utils/common.js"
	
	import noData from '@/components/noData.vue'
	
	export default {
		components:{
			tabBar,
			signupCard3,
			wybLoading,
			noData
		},
		data(){
			return{
				currentPage: 1, //当前页数
				total: 0, //总数
				size: 10, //每页条数
				loading: false,
				tableData: [] ,//表格数据
				status: 'loadmore',
			}
		},
		methods:{
			async API_list(current, size) {
				let result = {
					page: {
						current, //第几页
						size //每页条数
					}
				}
				return await list(result)
			},
			goDetails(row) { //查看详细
				console.log(row)
			},
			zkz(row) {//打印准考证
				window.location.href = BASE_URL + row.admission
			},
			zs(row) {//打印证书
				// console.log(row.qualification)
				window.location.href = BASE_URL + row.qualification
			},
			stateFilter(arr) { //过滤状态
				return arr.map((item) => {
					let obj = {}
					if (item.state === 1) {
						item.state = "待审核"
						obj = item
					} else if (item.state === 2) {
						item.state = "审核通过"
						obj = item
					} else if (item.state === 3) {
						item.state = "审核不通过"
						obj = item
					} else if (item.state === 4) {
						item.state = "已缴费"
						obj = item
					} else if (item.state === 5) {
						item.state = "已出准考证"
						obj = item
					}else if (item.state === 6) {
						item.state = "已出证书"
						obj = item
					}
					return obj
				})
			}
		},
		async onLoad() { //激活状态
			this.$refs.loading.showLoading()
			let res = await this.API_list(this.currentPage, this.size)
		
			let {
				current,
				records
			} = res.data.data
			this.currentPage = current
			this.total = records.length
			this.tableData = this.stateFilter(records)
			this.$refs.loading.hideLoading()
		},
		async onReachBottom(){//上拉加载
			if(this.tableData.length >= this.total){
				this.status = 'nomore';
				return
			}else{
				this.status = 'loading';
				this.current = ++this.current
				let res = await this.API_list(this.size,this.current)
				let {current,records} = res.data.data
				this.tableData.push(...records) 
			}
		}
	}
</script>

<style lang="scss" scoped>
	page,.certificate{
		height: 100%;
	}
</style>
